The need for data replication in a database system, particularly a distributed database system, is well known in the art. To ensure data consistency, modifications to different copies of a table must be replicated across all copies. To facilitate the updating of the table copies, timestamps are typically used to indicate which rows have been modified since the last update. Conventionally, a timestamp column that is automatically updated each time a row is modified is provided for this purpose. If the timestamp value in the timestamp column is later than the time of the last update, then that row has been modified since the last update.
Applications commonly use this timestamp column for controlling optimistic locking schemes as follows: the application retrieves one or more rows from the table, including the timestamp column; the application logically or physically disconnects from the database system; the application makes updates to the rows that were retrieved from the database; and sometime later, the application reconnects to the database so that it can record the updates in the database.
Before sending each update, the application retrieves the row from the database to validate that the timestamp column has not changed since the data was originally retrieved. If the timestamp column is unchanged, the application can safely record the update for that row. If the timestamp column is not the same, the disconnected update fails, and the application has to re-drive the update process using the modified data row.
As disconnected update models become more pervasive, the value of having an automatically updated timestamp column is growing. However, the addition of a timestamp column has several drawbacks. First, it requires additional CPU cost to maintain the timestamp column in each data row. Second, some tables may not be updated very frequently, so it may not be worthwhile to require the additional space for the timestamp in every row. Third, if the timestamp column has to be explicitly added to the table by the user, shrink-wrapped client applications cannot assume that the timestamp column will necessarily be present, since the user may have chosen not to add the timestamp column. So, client applications will be reluctant to exploit this feature of the database. Fourth, having an explicit column for the timestamp is also inconvenient for cases where some applications need the extra column while others do not. For example, adding the extra timestamp column for one application might cause problems for other existing applications that didn't expect this extra column to be part of the table schema.
Accordingly, there exists a need for an improved automatically updated timestamp for database systems. The improved timestamp should require low overhead, be available for all tables in a database system, and avoid problems for applications that do not expect a timestamp column. The present invention addresses such a need.